﻿using System;
using System.Data;

using System.Collections;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class ThucDonDAO : DataProvider
    {
        public ArrayList getDsThucDon()
        {
            connect();
            string sql = "select * from ThucDon";
            adapter = new SqlDataAdapter(sql, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            ArrayList arr = ConvertDataSetToArrayList(dataset);
            disconnect();
            return arr;
        }

        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            ThucDonDTO tdDTO = new ThucDonDTO();
            tdDTO.STT = int.Parse(dt.Rows[i][0].ToString());
            tdDTO.SOLUONG = int.Parse(dt.Rows[i][1].ToString());
            tdDTO.NGAYAPDUNG = DateTime.Parse(dt.Rows[i][2].ToString());
            tdDTO.BUOIAPDUNG = dt.Rows[i][3].ToString();

            return (object)tdDTO;
        }

        public ArrayList TimKiem(DateTime thoigian)
        {
            connect();
            string sql = "select * from ThucDon where ngay_ap_dung = '" + thoigian + "'";
            adapter = new SqlDataAdapter(sql, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            ArrayList arr = ConvertDataSetToArrayList(dataset);
            disconnect();
            return arr;
        }
    }
}
